package model;

import java.math.BigDecimal;
import java.util.Date;

public class SpecialDeal {
	private Airport departureAirport;
	private Airport arrivalAirport;
	private BigDecimal cost;
	private Date departureDate;
	private Date arrivalDate;

	// --- Getters,Setters,Constructors ----------------------------------------
	public SpecialDeal(Airport departureAirport, Airport arrivalAirport,
			BigDecimal cost, Date departureDate, Date arrivalDate) {
		this.departureAirport = departureAirport;
		this.arrivalAirport = arrivalAirport;
		this.cost = cost;
		this.departureDate = departureDate;
		this.arrivalDate = arrivalDate;
	}

	public Airport getDepartureAirport() {
		return departureAirport;
	}

	public Airport getArrivalAirport() {
		return arrivalAirport;
	}

	public BigDecimal getCost() {
		return cost;
	}

	public Date getDepartureDate() {
		return departureDate;
	}

	public Date getArrivalDate() {
		return arrivalDate;
	}

	// --- Methods -------------------------------------------------------------
	public boolean isValidOnDate(Date date) {
		if (date == null) {
			throw new IllegalArgumentException("Date must not be null!");
		}
		// create defensive copy, because Date is not immutable
		Date cDate = new Date(date.getTime());
		boolean checkDepartureDate = cDate.equals(getDepartureDate())
				|| cDate.after(getDepartureDate());
		boolean checkArrivalDate = cDate.equals(getArrivalDate())
				|| cDate.before(getArrivalDate());
		if (checkDepartureDate && checkArrivalDate) {
			return true;
		}
		return false;
	}

	public boolean isValidNow() {
		return isValidOnDate(new Date());
	}
}
